"""
两个线程，交替输出1-100
"""
import threading


class Foo:
    def __init__(self):
        self.lock1 = threading.Lock()
        self.lock2 = threading.Lock()
        self.lock1.acquire()

    def print1(self):
        for v in range(1, 100, 2):
            self.lock2.acquire()
            print(v)
            self.lock1.release()

    def print2(self):
        for v in range(2, 101, 2):
            self.lock1.acquire()
            print(v)
            self.lock2.release()


if __name__ == '__main__':
    try:
        f = Foo()
        t1 = threading.Thread(target=f.print1)
        t2 = threading.Thread(target=f.print2)
        t1.start()
        t2.start()
    except:
        print("Error: 无法启动线程")
